/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.leulounge.views;

import com.leulounge.control.Login;
import com.leulounge.model.Product;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Andres Godoy
 */
public class Products extends javax.swing.JFrame {

    public DefaultTableModel platesModel;
    public DefaultTableModel bottlesModel;
    public DefaultTableModel drinksModel;
    public DefaultTableModel coctailsModel;
    public DefaultTableModel othersModel;
    
    /**
     * Creates new form Inventory
     */
    public Products() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        plates = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        bottles = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        drinks = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        coctails = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        others = new javax.swing.JTable();
        productAdd = new javax.swing.JButton();
        productDelete = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        productLoad = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        productUnload = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(153, 153, 153));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.LEFT);

        plates.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Producto", "Tipo", "Descripcion", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        plates.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(plates);
        if (plates.getColumnModel().getColumnCount() > 0) {
            plates.getColumnModel().getColumn(0).setResizable(false);
            plates.getColumnModel().getColumn(0).setPreferredWidth(200);
            plates.getColumnModel().getColumn(1).setResizable(false);
            plates.getColumnModel().getColumn(1).setPreferredWidth(100);
            plates.getColumnModel().getColumn(2).setResizable(false);
            plates.getColumnModel().getColumn(2).setPreferredWidth(300);
            plates.getColumnModel().getColumn(3).setResizable(false);
            plates.getColumnModel().getColumn(3).setPreferredWidth(100);
            plates.getColumnModel().getColumn(3).setHeaderValue("Precio");
        }

        jTabbedPane1.addTab("Platos", jScrollPane1);

        bottles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Producto", "Tipo", "Descripcion", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        bottles.getTableHeader().setReorderingAllowed(false);
        jScrollPane2.setViewportView(bottles);
        if (bottles.getColumnModel().getColumnCount() > 0) {
            bottles.getColumnModel().getColumn(0).setResizable(false);
            bottles.getColumnModel().getColumn(0).setPreferredWidth(200);
            bottles.getColumnModel().getColumn(1).setResizable(false);
            bottles.getColumnModel().getColumn(1).setPreferredWidth(100);
            bottles.getColumnModel().getColumn(2).setResizable(false);
            bottles.getColumnModel().getColumn(2).setPreferredWidth(300);
            bottles.getColumnModel().getColumn(3).setResizable(false);
            bottles.getColumnModel().getColumn(3).setPreferredWidth(100);
            bottles.getColumnModel().getColumn(3).setHeaderValue("Precio");
        }

        jTabbedPane1.addTab("Botellas", jScrollPane2);

        drinks.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Producto", "Tipo", "Descripcion", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        drinks.getTableHeader().setReorderingAllowed(false);
        jScrollPane3.setViewportView(drinks);
        if (drinks.getColumnModel().getColumnCount() > 0) {
            drinks.getColumnModel().getColumn(0).setResizable(false);
            drinks.getColumnModel().getColumn(0).setPreferredWidth(200);
            drinks.getColumnModel().getColumn(1).setResizable(false);
            drinks.getColumnModel().getColumn(1).setPreferredWidth(100);
            drinks.getColumnModel().getColumn(2).setResizable(false);
            drinks.getColumnModel().getColumn(2).setPreferredWidth(300);
            drinks.getColumnModel().getColumn(3).setResizable(false);
            drinks.getColumnModel().getColumn(3).setPreferredWidth(100);
            drinks.getColumnModel().getColumn(3).setHeaderValue("Precio");
        }

        jTabbedPane1.addTab("Tragos", jScrollPane3);

        coctails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Producto", "Tipo", "Descripcion", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        coctails.getTableHeader().setReorderingAllowed(false);
        jScrollPane4.setViewportView(coctails);
        if (coctails.getColumnModel().getColumnCount() > 0) {
            coctails.getColumnModel().getColumn(0).setResizable(false);
            coctails.getColumnModel().getColumn(0).setPreferredWidth(200);
            coctails.getColumnModel().getColumn(1).setResizable(false);
            coctails.getColumnModel().getColumn(1).setPreferredWidth(100);
            coctails.getColumnModel().getColumn(2).setResizable(false);
            coctails.getColumnModel().getColumn(2).setPreferredWidth(300);
            coctails.getColumnModel().getColumn(3).setResizable(false);
            coctails.getColumnModel().getColumn(3).setPreferredWidth(100);
            coctails.getColumnModel().getColumn(3).setHeaderValue("Precio");
        }

        jTabbedPane1.addTab("Cocteles", jScrollPane4);

        others.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Producto", "Tipo", "Descripcion", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        others.getTableHeader().setReorderingAllowed(false);
        jScrollPane5.setViewportView(others);
        if (others.getColumnModel().getColumnCount() > 0) {
            others.getColumnModel().getColumn(0).setResizable(false);
            others.getColumnModel().getColumn(0).setPreferredWidth(200);
            others.getColumnModel().getColumn(1).setResizable(false);
            others.getColumnModel().getColumn(1).setPreferredWidth(100);
            others.getColumnModel().getColumn(2).setResizable(false);
            others.getColumnModel().getColumn(2).setPreferredWidth(300);
            others.getColumnModel().getColumn(3).setResizable(false);
            others.getColumnModel().getColumn(3).setPreferredWidth(100);
            others.getColumnModel().getColumn(3).setHeaderValue("Precio");
        }

        jTabbedPane1.addTab("Otros", jScrollPane5);

        productAdd.setText("Agregar");

        productDelete.setText("Eliminar");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 174, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 169, Short.MAX_VALUE)
        );

        productLoad.setText("Cargar");

        jButton4.setText("Cancelar");

        productUnload.setText("Retirar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 717, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(productLoad, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(productAdd, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(productDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addComponent(productUnload, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(111, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(productDelete, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(productAdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(productLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(productUnload, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jMenu1.setText("Archivo");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Editar");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    
    public void refreshProducts(){
        platesModel = (DefaultTableModel) plates.getModel();
        bottlesModel = (DefaultTableModel) bottles.getModel();
        drinksModel = (DefaultTableModel) drinks.getModel();
        coctailsModel = (DefaultTableModel) coctails.getModel();
        othersModel = (DefaultTableModel) others.getModel();
        
        int i=0;
        if(platesModel.getRowCount()!=0){
            while(i!=-1){
                try{
                    platesModel.removeRow(platesModel.getRowCount()-1);
                }catch(Exception e){
                    i=-1;
                }
            }
        }
        
        i=0;
        if(bottlesModel.getRowCount()!=0){
            while(i!=-1){
                try{
                    bottlesModel.removeRow(bottlesModel.getRowCount()-1);
                }catch(Exception e){
                    i=-1;
                }
            }
        }
        
        i=0;
        if(drinksModel.getRowCount()!=0){
            while(i!=-1){
                try{
                    drinksModel.removeRow(drinksModel.getRowCount()-1);
                }catch(Exception e){
                    i=-1;
                }
            }
        }
        
        i=0;
        if(coctailsModel.getRowCount()!=0){
            while(i!=-1){
                try{
                    coctailsModel.removeRow(coctailsModel.getRowCount()-1);
                }catch(Exception e){
                    i=-1;
                }
            }
        }
        
        i=0;
        if(othersModel.getRowCount()!=0){
            while(i!=-1){
                try{
                    othersModel.removeRow(othersModel.getRowCount()-1);
                }catch(Exception e){
                    i=-1;
                }
            }
        }
        
        try{
            for (Product product : Login.inventory.getInventory()){
                switch (product.getType()){
                    case "plato":
                        platesModel.addRow(new Object[]{product.getName(), product.getType(), product.getDescription(), product.getPrice()});
                        break;
                    case "botella":
                        bottlesModel.addRow(new Object[]{product.getName(), product.getType(), product.getDescription(), product.getPrice()});
                        break;
                    case "trago":
                        drinksModel.addRow(new Object[]{product.getName(), product.getType(), product.getDescription(), product.getPrice()});
                        break;
                    case "coctel":
                        coctailsModel.addRow(new Object[]{product.getName(), product.getType(), product.getDescription(), product.getPrice()});
                        break;
                    case "otro":
                        othersModel.addRow(new Object[]{product.getName(), product.getType(), product.getDescription(), product.getPrice()});
                        break;
                    default:
                        break;
                }
            }
            
        }catch(Exception e){
            System.out.println("Error: "+e);
        }
    }
    
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable bottles;
    private javax.swing.JTable coctails;
    private javax.swing.JTable drinks;
    private javax.swing.JButton jButton4;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable others;
    private javax.swing.JTable plates;
    private javax.swing.JButton productAdd;
    private javax.swing.JButton productDelete;
    private javax.swing.JButton productLoad;
    private javax.swing.JButton productUnload;
    // End of variables declaration//GEN-END:variables
}
